<template>
	<view>
		<view class="cu-form-group" v-for="(item,index) in settingList" :key="index">
			<view class="cu-form-box" @tap="showModal(index)">
				<view class="title">{{item.Default_Name}}</view>
				<view class="title1 ">{{item.Default_Value}}</view>
			</view>
			<view class="" v-if="item.Default_Value.length>0" @tap="clearInput(index)">
				<text class="cuIcon-close"></text>
			</view>
		</view>
		<view class="cu-modal" :class="modal?'show':'hide'" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">供应商选择</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<radio-group class="block" @change="gysChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in GYSList" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="title1">{{item.ClientName}}</view>
								<radio class="round" :class="radio=='radio'?'checked':''" :checked="radio=='radio'?true:false" :value="item.ClientName"></radio>
								<!-- <jiuaiCheckbox @change='changeBox' :value="item.value" :checked="item.checked"></jiuaiCheckbox> -->
							</label>
						</view>
					</view>
				</radio-group>
			</view>
		</view>
		<!--客户model-->
		<view class="cu-modal" :class="CustomerModal?'show':'hide'" @tap="hideModal1">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">客户选择</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<radio-group class="block" @change="CustomerChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in GYSList" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="title1">{{item.ClientName}}</view>
								<radio class="round" :class="radio=='radio'?'checked':''" :checked="radio=='radio'?true:false" :value="item.ClientName"></radio>
								<!-- <jiuaiCheckbox @change='changeBox' :value="item.value" :checked="item.checked"></jiuaiCheckbox> -->
							</label>
						</view>
					</view>
				</radio-group>
			</view>
		</view>
		<!--业务员model-->
		<view class="cu-modal" :class="YWYModal?'show':'hide'" @tap="hideModal2">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">业务员选择</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<radio-group class="block" @change="EChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in EmpList" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="title1">{{item.OperatorName}}</view>
								<radio class="round" :class="radio=='radio'?'checked':''" :checked="radio=='radio'?true:false" :value="item.OperatorName"></radio>
								<!-- <jiuaiCheckbox @change='changeBox' :value="item.value" :checked="item.checked"></jiuaiCheckbox> -->
							</label>
						</view>
					</view>
				</radio-group>
			</view>
		</view>
		<!--仓库model-->
		<view class="cu-modal" :class="StockModal?'show':'hide'" @tap="hideModal3">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">仓库选择</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<radio-group class="block" @change="StockChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in storeList" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="title1">{{item.StoreName}}</view>
								<radio class="round" :class="radio=='radio'?'checked':''" :checked="radio=='radio'?true:false" :value="item.StoreName"></radio>
								<!-- <jiuaiCheckbox @change='changeBox' :value="item.value" :checked="item.checked"></jiuaiCheckbox> -->
							</label>
						</view>
					</view>
				</radio-group>
			</view>
		</view>
	</view>

</template>

<script>
	import * as Api from '@/syApis/syBb/apis.js';
	import * as Api1 from '@/syApis/sySet/sySet.js';

	export default {
		created() {
			let date = new Date();
			this.GetStoreMessage();
			this.GetOperatorMessage();
			this.GetClientMessage();
			this.getDefaultSettingInfo();
		},
		methods: {
			//获取默认设置信息
			getDefaultSettingInfo() {
				let data = {};
				var that = this;
				Api1.Get_Set_Default(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							// //console.tablele(res.data.ResultMsg);
							//赋值数组
							that.settingList = res.data.ResultMsg;

						}
					} else {

					}
				})
			},
			//获取供应商信息
			GetClientMessage() {
				let data = {};
				var _this = this;
				Api.GetClientMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.List1 = [];
							_this.GYSList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.List1.push(res.data.ResultMsg[item].ClientName);
							}
						}
					} else {
						Api.ShowTip("服务器开小差了");
					}
				})
			},
			//获取员工档案
			GetOperatorMessage() {
				let data = {};
				var _this = this;
				Api.GetOperatorMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.ClientNameList = [];
							_this.EmpList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.ClientNameList.push(res.data.ResultMsg[item].OperatorName);
							}
						}
					} else {
						Api.ShowTip("服务器开小差了");
					}
				})
			},

			//获取仓库档案
			GetStoreMessage() {
				let data = {};
				var _this = this;
				Api.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.List = [];
							_this.storeList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.List.push(res.data.ResultMsg[item].StoreName);
							}
						}
					} else {
						Api.ShowTip("服务器开小差了");
					}
				})
			},
			gysChange(e) {
				console.log(e)
				this.modal = false;
				this.settingList[0].Default_Value = e.detail.value;
			},
			CustomerChange(e) {
				console.log(e)
				this.CustomerModal = null;
				this.settingList[1].Default_Value = e.detail.value;
			},
			EChange(e) {
				console.log(e)
				this.YWYModal = null;
				this.settingList[2].Default_Value = e.detail.value;
			},
			StockChange(e) {
				console.log(e)
				this.StockModal = null;
				this.settingList[3].Default_Value = e.detail.value;
			},
			//清除默认设置内容
			clearInput(selectIndex) {
				this.settingList[selectIndex].Default_Value = "";
			},
			hideModal(selectIndex) {
				this.modal = false;
			},
			hideModal1(selectIndex) {
				this. CustomerModal= false;
			},
			hideModal2(selectIndex) {
				this.YWYModal = false;
			},
			hideModal3(selectIndex) {
				this.StockModal = false;
			},
			showModal(e) {
				console.log(e)
				if (e == 0) {
					this.modal = true
					for (let item in this.GYSList) {
						if (item == e.index) {
							this.ClientName = this.GYSList[item].ClientID;
						}
					}
				} else if (e == 1) {
					this.CustomerModal = true
					for (let item in this.GYSList) {
						if (item == e.index) {
							this.ClientName = this.GYSList[item].ClientID;
						}
					}
				} else if (e == 2) {
					this.YWYModal = true
					for (let item in this.EmpList) {
						if (item == e.index) {
							this.EName = this.EmpList[item].OperatorID;
						}
					}
				} else if (e == 3) {
					this.StockModal = true
					// console.log(selectindex)
					for (let item in this.storeList) {
						if (item == e.index) {
							this.SName = this.storeList[item].StoreID;
						}
					}
				} else if (e == 4) {
					// console.log(selectindex)
				}
			},
		},
		data() {
			return {
				settingList: [],
				// modalName: null,
				modal: false,
				CustomerModal:false,
				StockModal:false,
			    YWYModal:false,
				ClientNameList: [],
				EmpList: [],
				List: [],
				storeList: [],
				GYSList: [],
				List1: [],
				radio: '',
			}
		}
	}
</script>

<style>
	pages {
		background: #FFFFFF;
	}

	.cu-form-box {
		display: flex;
		align-items: center;
		width: 100%;
	}

	.title {
		min-width: 160rpx;
		text-align: right;
	}

	.title1 {
		padding-right: 14px;
		font-size: 14px;
		position: relative;
		height: 28px;
		line-height: 28px;
	}
</style>
